﻿###############多进程##############
# from multiprocessing import Process
# from multiprocessing import Pool;
# def run_proc():
	# print("hello");
# p = Process(target = run_proc);#多进程
# if __name__ == '__main__':#当前文件作为脚本的时候执行
	# p.start();
	# p.join();
# ######pool进程池#########
# def long_time_task(name):
	# print(name,"start");
	# time.sleep(3);
	# print(name,"end");

# if __name__ == "__main__":
	# print("执行到");
	# p = Pool(4);
	# for i in range(4):
		# # print(i);
		# p.apply_async(long_time_task,args = (i,));
	# p.close();
	# p.join();

#######子进程###########
####运行window命令#######
# import subprocess
# r = subprocess.call(['nslookup','www.baidu.com']);

#######进程间通信 利用Queue###########
# from multiprocessing import Process,Queue
# def write(q):
	# q.put("A");

# def read(q):
	# while True:
		# value = q.get(True);
		# print(value);
		
# if __name__ == "__main__":
	# q = Queue();
	# pw = Process(target = write,args=(q,));
	# pr = Process(target = read,args=(q,));
	# pr.start();
	# pw.start();
	# pw.join();

########多线程############################
# import time,threading;

# def loop():
	# n = 0;
	# while n<5:
		# n = n + 1;
		# print(n);
# t = threading.Thread(target = loop);
# t.start();
# t.join();

##多线程锁Lock###
import threading
blance = 0;
lock = threading.Lock();

def change_i():
	global blance;
	blance = blance + 1;
	blance = blance -1;
	
def run_thread():
	for i in range(100):
		#获取锁
		lock.acquire();
		try:
			change_i();
		finally:
			lock.release();
			
t = threading.Thread(target = run_thread)
t.start();
t.join();
print(blance);